<template>
  <div>
    <h2>组合api的vuex</h2>
    <p>{{ count }}</p>
    <button @click="handleClick">btn</button>
  </div>
</template>

<script>
import { computed } from "vue";
import { useStore } from "vuex";
export default {
  setup() {
    const store = useStore();

    // const count = ref(store.state.count);
    // vuex需要使用计算属性引入
    const count = computed(() => {
      return store.state.index.count;
    });

    const handleClick = () => {
      // 命名空间的 模块名/事件名
      store.commit("index/add");
    };

    return {
      count,
      handleClick,
    };
  },
};
</script>
